package com.example.mrzhou.srtfoodapplication;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Mr.Zhou on 2017/1/23.
 */

public class FlavorModTwoLayout extends LinearLayout {

    private List<Flavor> flavorList = new ArrayList<Flavor>();

    public FlavorModTwoLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.flavor_mod, this);
        initFlavor();
        FlavorAdapter adapter = new FlavorAdapter(getContext(), R.layout.flavor_item,flavorList);
        ListView listView = (ListView) findViewById(R.id.flavor_list);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Flavor flavor = flavorList.get(position);
            }
        });
    }

    private void initFlavor() {

        Flavor [] flavor = new Flavor[10];
        for (int i=0;i<10;i++){
            flavor[i] = new Flavor();
        }
        flavor[0].setName("1.子城外婆家 · 鱼香肉丝");
        flavor[1].setName("2.鲈鱼 · 水煮鱼");
        flavor[2].setName("3.老蜀人 · 宫保鸡丁");
        flavor[3].setName("4.老蜀人 · 夫妻肺片");
        flavor[4].setName("5.金川味 · 辣子鸡丁");
        flavor[5].setName("6.合味道 · 麻婆豆腐");
        flavor[6].setName("7.弄堂菜馆 · 麻辣小龙虾");
        flavor[7].setName("8.金川味 · 香辣鳝鱼");
        flavor[8].setName("9.子城外婆家 · 鱼香肉丝");
        flavor[9].setName("10.金饭碗 · 咕佬肉");
        for (int i=0;i<10;i++){
            flavorList.add(flavor[i]);
        }
    }
}
